﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CapaPresentacion.Controles
{
    /// <summary>
    /// Lógica de interacción para LabelAndDecimalComaTextBox.xaml
    /// </summary>
    public partial class LabelAndDecimalComaTextBox : UserControl
    {

        public static readonly DependencyProperty TextoProperty = DependencyProperty.Register("Texto", typeof(string), typeof(LabelAndDecimalComaTextBox));

        public LabelAndDecimalComaTextBox()
        {
            InitializeComponent();
            this.AddHandler(LabelAndDecimalComaTextBox.KeyDownEvent, new RoutedEventHandler(HandleHandledKeyDown), true);

            Binding b = new Binding();
            b.Source = this;
            b.Path = new PropertyPath(LabelAndDecimalComaTextBox.TextoProperty);
            b.Mode = BindingMode.TwoWay;


            this.txt.SetBinding(TextBox.TextProperty, b);
        }


        public void HandleHandledKeyDown(object sender, RoutedEventArgs e)
        {
            KeyEventArgs ke = e as KeyEventArgs;
            if (ke.Key >= Key.D0 && ke.Key <= Key.D9 || ke.Key >= Key.NumPad0 && ke.Key <= Key.NumPad9 || ke.Key == Key.OemComma)
            {
                ke.Handled = false;
            }
            else
                ke.Handled = true;

            if (ke.Key == Key.Space)
            {
                this.txt.Text = this.txt.Text.Replace(" ", "");
            }

            if (ke.Key == Key.LeftCtrl || ke.Key == Key.RightCtrl)
            {
                e.Handled = true;
                Clipboard.Clear();
            }

            if (ke.Key == Key.Tab)
                ke.Handled = false;

        }

        public int Longitud
        {
            set { txt.MaxLength = value; }
        }

        public string Etiqueta
        {
            get { return lbl.Content.ToString(); }

            set { lbl.Content = value; }
        }

        public FontFamily TipoLetra
        {
            set { lbl.FontFamily = txt.FontFamily = value; }
        }


        public string Texto
        {
            get { return (string)GetValue(TextoProperty); }
            set { SetValue(TextoProperty, value); }
        }









    }
}
